package controller;

import command.FormCommand;
import entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

@Controller
@RequestMapping("/form")
public class FormController {

    @RequestMapping("/show")
    public String show(FormCommand formCommand){
        System.out.println("FormController.show()");

        formCommand.setT("abc");
        formCommand.setP("123");
        formCommand.setTa("aaaaaaaa");
        formCommand.setH("1");
        formCommand.setC(Arrays.asList("1","3"));
        formCommand.setCs(new String[]{"1","3"});
        formCommand.setUs(new Integer[]{2,3});
        formCommand.setR("2");
        formCommand.setS("2");
        
        return "form";
    }

    @RequestMapping("/submit")
    public String submit(FormCommand formCommand){
        System.out.println("FormController.submit()");

        System.out.println("formCommand.getT() = " + formCommand.getT());
        System.out.println("formCommand.getP() = " + formCommand.getP());
        System.out.println("formCommand.getTa() = " + formCommand.getTa());
        System.out.println("formCommand.getH() = " + formCommand.getH());
        System.out.println("formCommand.getC() = " + formCommand.getC());
        System.out.println("formCommand.getCs() = " + Arrays.toString(formCommand.getCs()));
        System.out.println("formCommand.getUs() = " + Arrays.toString(formCommand.getUs()));
        System.out.println("formCommand.getR() = " + formCommand.getR());
        System.out.println("formCommand.getS() = " + formCommand.getS());

        return "redirect:/form/show";
    }


    @ModelAttribute("map")
    public Map loadMap(){
        Map map=new HashMap();

        map.put("1","aaa");
        map.put("2","bbb");
        map.put("3","ccc");

        return map;
    }

    @ModelAttribute("users")
    public List<User> loadUsers(){
        List<User> users=new ArrayList<User>();
        users.add(new User(1,"aaa","111","11111111",23));
        users.add(new User(2,"bbb","222","22222222",21));
        users.add(new User(3,"ccc","333","33333333",26));

        return users;
    }












}
